"""
    scrapy initial urls has 2 type of writings
    1,constants start_urls,and define a function parse() is needed
    2,anather is to straight define a function:start_requests()
"""
import scrapy
class simpleurl(scrapy.Spider):
    name = "simpleurl"
    start_urls = [
        # another type of writting,no need to define a start_requests function
        'http://lab.scrapyd.cn/page/1/',
        'http://lab.scrapyd.cn/page/2/',
    ]

    # another type of writing for initialise url
    # def start_requests(self):
    #     urls = [
    #         # crawl pages through the urls defined below
    #         'http://lab.scrapyd.cn/page/1/',
    #         'http://lab.scrapyd.cn/page/2/',
    #     ]
    #     for url in urls:
    #         yield scrapy.Request(url=url,callback=self.parse)
    # if you are using the simple type to initialize urls,this function must be named :parse

    def parse(self,response):
        page = response.url.split("/")[-2]
        filename = 'mingyan-%s.html' % page
        with open(filename,'wb') as f:
            f.write(response.body)
        self.log('save file: %s' % filename)